package com.ksd.modules.members.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ksd.common.annotation.ApiLog;
import com.ksd.common.controller.BaseController;
import com.ksd.common.core.result.R;
import com.ksd.common.po.BatchIdsPO;
import com.ksd.common.web.annotation.RepeatSubmit;
import com.ksd.modules.members.po.AdminUserWalletCodeSavePO;
import com.ksd.modules.members.po.AdminUserWalletCodeSearchPO;
import com.ksd.modules.members.service.IAdminUserWalletCodeService;
import com.ksd.modules.members.vo.AdminUserWalletCodeVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 平台up主用户 前端控制器
 * </p>
 *
 * @author Auto Generator
 * @since 2023-08-15
 */
@RestController
public class AdminUserWalletCodeController extends BaseController {


    @Autowired
    private IAdminUserWalletCodeService adminUserWalletCodeService;

    /**
     * 查询首页钱包兑换码模板接口
     * @param adminUserWalletCodeSearchPO
     * @return
     */
    @PostMapping("/users/wallet/code/list")
    public R<Page<AdminUserWalletCodeVo>> findAdminUserWalletCodes(@Validated @RequestBody AdminUserWalletCodeSearchPO adminUserWalletCodeSearchPO){
        return R.data(adminUserWalletCodeService.findAdminUserWalletCodes(adminUserWalletCodeSearchPO));
    }


    /**
     * 【钱包兑换码】 - 根据id查询明细
     * @param id
     * @return
     */
    @PostMapping("/users/wallet/code/get/{id}")
    public R<AdminUserWalletCodeVo> getAdminUserWalletCodeById(@PathVariable("id")Long id){
        return R.data(adminUserWalletCodeService.getAdminUserWalletCodeById(id));
    }


    /**
     * 【钱包兑换码】- 批量物理删除
     *
     * @return
     */
    @PostMapping("/users/wallet/code/batch/remove")
    @ApiLog("【钱包兑换码】- 批量物理删除")
    @RepeatSubmit
    public R<Boolean> batchRemovesAdminUserWalletCode(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(adminUserWalletCodeService.batchRemovesAdminUserWalletCode(batchIdsPO));
    }

    /**
     * 【钱包兑换码】- 根据ID恢复删除
     * @param id
     * @return
     */
    @PostMapping("/users/wallet/code/remove/{id}")
    @ApiLog("【钱包兑换码】- 根据ID恢复删除")
    public R<Boolean> removeAdminUserWalletCodeById(@PathVariable("id")Long id){
        return R.data(adminUserWalletCodeService.removeAdminUserWalletCodeById(id));
    }


    /**
     * 【钱包兑换码】 - 创建兑换码
     * @param adminUserWalletCodeSavePO
     * @return
     */
    @PostMapping("/users/wallet/code/create")
    @ApiLog("【钱包兑换码】 - 创建兑换码")
    @RepeatSubmit
    public R<Boolean> createBatchCode(@Validated @RequestBody AdminUserWalletCodeSavePO adminUserWalletCodeSavePO){
        return R.data(adminUserWalletCodeService.createBatchCode(adminUserWalletCodeSavePO));
    }


    /**
     * 【钱包兑换码】- 修改状态
     *
     * @return
     */
    @PostMapping("/users/wallet/code/status/{id}/{field}")
    @ApiLog("【钱包兑换码】- 修改状态")
    @RepeatSubmit
    public R<Boolean> updateStatus(
            @PathVariable("id") Long id,
            @PathVariable("field") String field,
            @RequestParam("value") String value
    ) {
        if(StringUtils.isNumeric(value)) {
            return R.data(adminUserWalletCodeService.updateStatus(id, field, Integer.parseInt(value)));
        }else{
            return R.data(adminUserWalletCodeService.updateStatusStr(id, field, String.valueOf(value)));
        }
    }
}
